import { defineStore } from "pinia";
import type { categoryStoreStateType } from './interface/category';
import { reqC1List, reqC2List, reqC3List } from '@/api/product/attr/attr';
let useCategoryStore = defineStore('category', {
    state: (): categoryStoreStateType => ({
        //存储一级分类的数据
        c1List: [],
        c2List: [],
        c3List: [],
        //收集一级分类的id
        c1Id: '',
        c2Id: '',
        c3Id: '',
    }),

    actions: {
        async getC1List() {
            //获取一级分类的数据
            let result = await reqC1List();
            this.c1List = result;
        },
        async getC2List() {
            this.c2Id = '';
            this.c3Id = '';
            this.c2List = [];
            this.c3List = [];
            let result = await reqC2List(this.c1Id);
            this.c2List = result;
        },
        async getC3List() {
            this.c3Id = '';
            this.c3List = [];
            let result = await reqC3List(this.c2Id);
            this.c3List = result;
        }
    }
});
export default useCategoryStore;